package com.sams.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sams.entity.Baseinfo;
import com.sams.service.BaseInfoService;
import com.sams.util.SamResult;

@RequestMapping("/ztree")
@Controller
public class ZTreeController {

	@Autowired
	private BaseInfoService service;
	
	@ResponseBody
	@RequestMapping("/getBaseInfo")
	public List<Baseinfo> getZtree(Integer pid) {
		List<Baseinfo> list = service.listAll(pid);
		System.out.println(list);
		return list;
	}
	@ResponseBody
	@RequestMapping("/delete")
	public SamResult delete(Integer id) {
		int count = service.delete(id);
		return new SamResult(200, "删除成功", null);
	}
	
	@ResponseBody
	@RequestMapping("/getNameByType")
	public List<Baseinfo> getNameByType(Integer typeid) {
		List<Baseinfo> list = service.getNameByType(typeid);
		System.out.println(list);
		return list;
	}
	
	@ResponseBody
	@RequestMapping("/selectAllChild")
	public List<Baseinfo> selectAllChild() {
		List<Baseinfo> list = service.selectAllChild();
		//System.out.println(list);
		return list;
	}
	
	 
	@ResponseBody
	@RequestMapping("/add")
	public SamResult add(String name,Integer pid,Integer type,Integer id) {
		Baseinfo baseinfo = new Baseinfo();
		baseinfo.setName(name);
		baseinfo.setpId(pid);
		baseinfo.setType(type);
		baseinfo.setId(id);//id 不为空就是修改
		 
			int count = service.add(baseinfo);
	 
		return new SamResult(200, "操作成功", null);
	}
	
}
